
package com.controller;
 
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.model.UserData;

 
@Controller
@RequestMapping("/Dispatcher")
public class DispatcherController {
 
	
	@RequestMapping(method = RequestMethod.GET)
	public String messagePage(ModelMap model) {
		model.addAttribute("message", "userDataname must input \"Nam\"!");
		return "MessagePage";
	}
/*	 
	@RequestMapping(method = RequestMethod.POST)
	public String post(ModelMap model) {
		System.out.println("hihi");
		return "/confirm/Confirm";
	}
	*/
	@RequestMapping(value = "/getUserData", method = RequestMethod.POST)
	   public String getUserData(@ModelAttribute("SpringWeb")UserData userData, 
	   ModelMap model) {
	      if(userData.getUsername().equals("Nam")){
	    	  model.addAttribute("name", userData.getUsername());
		      model.addAttribute("age", userData.getAge());
		      model.addAttribute("email", userData.getEmail());
		      return "/confirm/Confirm";
	      }else{
	    	  model.addAttribute("message", "username must input \"Nam\"!");
	  		  return "MessagePage";
	      }
	   }
	
	/*
	@Override
	protected ModelAndView onSubmit(Object command) throws Exception {
		UserData userData = (UserData) command;
		System.out.println(userData.getUsername());
		return new ModelAndView("/confirm/Confirm","userData",userData);
	}
 */
}
